<body>
  响应式练习：<br />
  let a = 10;<br />
  let b = a * 10;<br />
  题目： 保持 b永远是a得十倍 <br />

</body>

<script>
  // 依赖跟踪
  var activeEffect;
  class Dep {
    subscribers = new Set()
    depend() {
      if (activeEffect) {
        this.subscribers.add(activeEffect);
      }
    }
    notify() {
      this.subscribers.forEach(effect => {
        effect()
      })
    }
  }

  function reactive(raw) {
    Object.keys(raw).forEach((key) => {
      var dep = new Dep()
      let value = raw[key]
      Object.defineProperty(raw, key, {
        get() {
          dep.depend()
          return value
        },
        set(newValue) {
          value = newValue
          dep.notify()
        }

      })
    })
    return raw
  }

  // 副作用函数
  function watchEffect(effect) {
    activeEffect = effect
    effect()
    activeEffect = null
  }

  var state = reactive({
    count: 0
  })

  watchEffect(() => {
    console.log(state.count)
  }) // 0

  state.count++ // 1

</script>